function [  ] = VisualizeHelicopter( x, idx, H, dt, record, filepath )

    if(nargin  < 4)
        record = 0;
        filepath = '';
    end
    
    sock = heliConnect('localhost', 12345);

    
    if(record)
        heliStartRecord(sock, filepath);
    end
    
    heliOffset = [0, 0, -10]';
    cameraOffset = [0, 3, 0]';
    cameraInterpolation = 0.9;
    ivCameraInterpolation = 1.0 - cameraInterpolation;
    cameraOrientation = [0, 0, 0, 1]';
    lastNed = heliOffset + cameraOffset;
    for t = 1:H
        ned = x(idx.ned, t) + heliOffset;
        q = x(idx.q, t);
        u = x(idx.inputs);
        heliSetPosition(sock, ned, q);
        heliSetRotorSpeed(sock, u(3) * 30);
        cameraPos = (ivCameraInterpolation * ned + cameraInterpolation * lastNed) + cameraOffset;
        heliSetCameraPosition(sock, cameraPos, cameraOrientation);
        pause(dt);
        lastNed = cameraPos;
    end
    
    if(record)
        heliStopRecord(sock, filepath);
    end

end

